#ifndef _SypEngine_H
#define _SypEngine_H

#include "GE_Base.h"
#include <sstream>
#include <assert.h>
namespace Syp
{
///SypEngine is a wrapper around all of the subsystems and provides additional shared functionality over the core subsystems. It also manages initialisation/deinitialisation of all the subsystems in the correct order.
class SYPAPI SypEngine
{
public:

	///A utility function which loads the contents of a file into the reference contents.
	static void loadFromFile(const String& filename, String& contents);
	///Creates a thread and returns a SYPThread handle to the thread.
	static SYPThread createThread(SYPThreadFunction function, void *arg);
	///Sets the Window Close Callback function. This will be called when the user closes the window.
	void setWindowCloseCallback(SYPWindowCloseFunction function);
	///Creates a Mutex and returns it
	SYPMutex createMutex();
	///Destroys a Mutex
	void destroyMutex(SYPMutex mutex);
	///Locks a Mutex
	static void lockMutex(SYPMutex mutex);
	///Unlocks a mutex
	static void unLockMutex(SYPMutex mutex);
	///creates the game Engine
	static void createSypEngine();
	///releases the game Engine and frees up memory
	static void releaseSypEngine();
	///returns reference to Game Engine
	static SypEngine& getSypEngine();
	
	~SypEngine();
	///Initialises Game Engine and all subsystems
	void init(const String& title,int width,int height,bool fullscreen,Font* sys = 0);

	///Runs the engine to do all takss required to produce a frame
	void run();

	///Returns the current version of Engine
	static float getVersion();
	
	///returns current Frame time
	inline double getCurrFrameTime()
	{
		return currFrame;
	};
	///returns elapsed Frame time
	inline double getElapsedTime()
	{
		return timeDiff;
	};
	///returns a bool which indicates whether a window is active
	inline bool windowIsActive()
	{
		return isActive;
	};
	///returns a bool which indicates whether a window is open
	inline bool windowIsOpen()
	{
		return isOpen;
	};
	
	///Returns a Reference to the system font.
	Font& getSysFontRef();

private:		
	///Whether the window is active
	bool isActive;
	///Whether the window is still open
	bool isOpen;
	///releases Game Engine and all subsystems
	void release();
	///Initialises core Effects/Passes
	void initCorePack();
	///Time of lastFrame
	double lastFrame;
	///Current Frame time
	double currFrame;
	///Time difference between 2 frames
	double timeDiff;
	///List of all Created Mutexes
	std::vector<SYPMutex> mutexes;
	///For the printing of FPS
	//std::ostringstream stream;
	///Renderer system pointer
	Renderer* rnd;	
	///Debug font used for screen output by engine/FPS
	Font* system;

	SYPWindowCloseFunction winClose;

	static int realWindowClose();


	float totalElapsed;
	PInt FPS;
	PInt showFPS;

	SypEngine():lastFrame(0.0)
	{
	};

	static SypEngine* ge;



};
}

#endif

